/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 07 - 17
 * Time: 15:13
 */
class Solution5 {
    public boolean isSymmetric(TreeNode root) {
        if(root == null) return true;
        return isSymmetricChild(root.left, root.right);
    }
    public boolean isSymmetricChild(TreeNode p, TreeNode q) {
        if((p == null) && (q == null)) {
            return true;
        }
        if((p == null && q != null) || (p != null && q == null)) {
            return false;
        }
        if(p.val != q.val) {
            return false;
        }
        return isSymmetricChild(p.left, q.right) && isSymmetricChild(p.right, q.left);
    }
}
